package com.lagou.controller;

import com.lagou.domain.Employee;
import com.lagou.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 查询所有用户
     * @param model
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll(Model model) {

        List<Employee> employeeList = employeeService.findAll();

        model.addAttribute("list", employeeList);

        return "empList";
    }

    /**
     * 新增一个用户
     * @param employee
     * @return
     */
    @RequestMapping("/save")
    public String save(Employee employee) {

        employeeService.save(employee);
        return "redirect:/employee/findAll";
    }
}
